package com.free.fs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.free.fs.mapper.SummaryMapper;
import com.free.fs.model.Summary;
import com.free.fs.service.SummaryService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SummaryServiceImpl extends ServiceImpl<SummaryMapper, Summary> implements SummaryService {

   @Autowired
    private SummaryMapper summaryMapper;
    @Override
    public IPage<Summary> getPage(int currentPage, int pageSize) {
        IPage page = new Page<>(currentPage,pageSize);
        return summaryMapper.selectPage(page,null);
    }

    @Override
    public IPage<Summary> getPage(int currentPage, int pageSize ,Summary summary) {
        LambdaQueryWrapper<Summary> lqw =new LambdaQueryWrapper<Summary>();
        lqw.like(Strings.isNotEmpty(summary.getTitle()),Summary::getTitle,summary.getTitle());
        lqw.like(Strings.isNotEmpty(summary.getName()),Summary::getName,summary.getName());
        lqw.like(Strings.isNotEmpty(summary.getTime()),Summary::getTime,summary.getTime());

        IPage page = new Page<>(currentPage,pageSize);
        return summaryMapper.selectPage(page,lqw);
    }
}
